<template>
	<div>
		<top-nav bgColor="white" title="我的工厂"  btnName="工厂管理"  :rightShow="true" returnPath="index2" rightPath="factoryManage" @fatherDo="sendParams"></top-nav>
		<section style="height: 3.2rem;"></section>
		<factory-item style=""
          v-for="item in factoryList"
          :key = "item.id"
          :id="item.id"
          :factoryName="item.factoryname"
          :address="item.adress"
          :contacts="item.contacts"
          :contactInfo="item.phone"
          :router="item.router"
          @sureDo="popSure"
         />
		<mu-dialog :open="isPop" title="提示" @close="close">
		           此操作将解除微信公众号与工厂账号的绑定, 是否解绑?
		    <mu-flat-button slot="actions" @click="close('cancel')" primary label="取消"/>
		    <mu-flat-button slot="actions" primary @click="close('sure')" label="确定"/>
		</mu-dialog>
	</div>
</template>

<script>
	 import BScroll from 'better-scroll'
	 import FactoryItem from '@/page/factory/factoryItem.vue'
	 	
	 import TopNav from '@/components/nav/topNav.vue'
	 export default {
	 	 components: {
		      TopNav,
		      FactoryItem
		 },
		 data(){
		 	return{
		 		factoryList: [],
//		        factoryName:'SB工厂',
//		        address:'山东济南高新区姚家',
//		        contacts:'薛冰',
//		        contactInfo:'15678886788',
		        path:{path:'factoryManage'},
		        isPop:false,
		        choiceId:''
			 }
		 },
		 mounted(){
		 	this.getServerList()
		 },
		 methods:{ 
		 	getServerList(){
		 		let that=this
			 	that.axios.get('/factoryUser/getFactoryList').then(function(response){
			 		console.info(response.data)
			 		that.factoryList=response.data.data
			 	}).catch(function(error){
			 		console.info(error)
			 	})
//			 	that.axios.get('/factory/getFactoryList').then(function(response){
//			 		console.info('123456')
//			 		console.info(response.data)
//			 	}).catch(function(error){
//			 		console.info(error)
//			 	})
		 	},	 		
		 	sendParams()
	 		{
	 		let that=this
	 		that.$router.push(
	 		{path:'factoryManage',
	 		name:'factoryManage',
			 params: { 
            }})
	 		},
	 		popSure(id){
	 			this.isPop=true
	 			this.choiceId=id
	 		},
		 	close(val){
		 		if(val=='sure'){
		 			let that=this
		 			that.axios.post('/factoryUser/deleteFactoryUser',{
						'factoryId':that.choiceId
						}).then(function(response){
					 		console.info(response.data)
					 		window.location.reload()
					 	}).catch(function(error){
					 		console.info(error)
					 	})
		 			}
		 		this.isPop=false
		 	}
		 }
	  }
</script>

<style>
</style>